package com.xavier.lotterysystem.dao.mapper;

import com.xavier.lotterysystem.dao.dataobject.UserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据邮箱查询绑定人数
     * @param email
     * @return
     */
    @Select("select count(*) from user where email = #{email}")
    int countByEmail(@Param("email") String email);

    /**
     * 根据手机号查询绑定人数
     * @param phoneNumber
     * @return
     */
    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    int countByPhone(@Param("phoneNumber") String phoneNumber);

    /**
     * 插入用户
     * @param userDO
     */
    @Insert("insert into user(user_name,email,phone_number,password,identity) values (#{userName},#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insert(UserDO userDO);
}
